
#定时脚本检测

import psutil,os,random,requests,time
from config import *
from helper import Helper
import requests
# 检测程序是否退出
def checkProc():

    # 获取进程列表
    procList = [process.as_dict(attrs=['pid', 'name'])['name'] for process in psutil.process_iter()]
    # 执行任务成
    exe = r'拼多多评价任务采集.exe'
    # 判断是否存在进行列表中
    if exe not in procList:

        #重启网卡
        resetNetwork()

        #发送请求任务查看IP是否被解封

        while True:

            # print( Helper.verifyAccess())

            # 验证成功
            if Helper.verifyAccess():

                # 重置被封任务状态
                data = {

                    'state':7
                }
                #回传数据证明被解封
                r = requests.post(url=domain_url['callback_task_url'],data=data)

                # print(r.json()['details']['code'])
                if r.status_code == 200 and r.json()['details']['code'] in [200,201]:

                    # print(r.json()['details']['code'])

                    pass

                    # 启动程序
                    os.system(r'拼多多评价任务采集.exe')

                break

            time.sleep(2)

    else:

        print('程序检测中,账号未被封禁.....')

# 重启网卡更换IP
def resetNetwork():

    # 断网指令
    CMD = 'Rasdial "拨号连接" /disconnect'

    os.system( CMD )

    while True:

        try:

            url = random.choice( urls )
            # 随机请求地址
            code = lambda :requests.get(url=url).status_code

            print( url )

            time.sleep(1)

            if code() == 200:
                #获取当前ip
                ip = lambda :requests.get(url='http://ip.42.pl/raw').text

                print('IP更换成功当前ip地址为:',ip())

                break

        except Exception as e:

            print('正在进行IP地址更换.....')

        time.sleep(2)



if __name__ == '__main__':

    while True:

        checkProc()

        time.sleep(30)




